import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:jinke/utils/util.dart';
import 'package:video_player/video_player.dart';

import 'index.dart';
import 'widgets/widgets.dart';

class VideoPlayerPage extends StatelessWidget {
  VideoPlayerPage({Key? key, this.url}) : super(key: key);
  final String? url;
  final controller = Get.put(VideoPlayerViewController());

  @override
  Widget build(BuildContext context) {
    var state = controller.state;
    if (url != null) {
      state.url = url!;
      controller.started();
    }
    return GetBuilder<VideoPlayerViewController>(
      builder: (_) {
        return SafeArea(
          child: Container(
            width: Get.width,
            height: 1.sw * 9 / 16,
            color: Colors.black,
            child: state.playerCtrl.value.isInitialized
                ? Chewie(controller: state.chewieCtrl!)
                : Center(
                    child: CircularProgressIndicator(
                      color: Colors.white,
                    ),
                  ),
          ),
        );
      },
    );
  }
}
